package cn.chencaiju.day08;

/**
 * @author haiming
 *
 */
public class Car implements Comparable<Car>{
	private String name;
	private float length;
	private float width;
	public Car() {
		super();
	}
	public Car(String name, float length, float width) {
		super();
		this.name = name;
		this.length = length;
		this.width = width;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public float getLength() {
		return length;
	}
	public void setLength(float length) {
		this.length = length;
	}
	public float getWidth() {
		return width;
	}
	public void setWidth(float width) {
		this.width = width;
	}
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Car [name=");
		builder.append(name);
		builder.append(", length=");
		builder.append(length);
		builder.append(", width=");
		builder.append(width);
		builder.append("]");
		return builder.toString();
	}
	@Override
	public int compareTo(Car o) {
		// TODO Auto-generated method stub
		if(this.length>o.length)
			return 1;
		if(this.length<o.length)
			return -1;
		return 0;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Float.floatToIntBits(length);
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + Float.floatToIntBits(width);
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Car other = (Car) obj;
		if (Float.floatToIntBits(length) != Float.floatToIntBits(other.length))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (Float.floatToIntBits(width) != Float.floatToIntBits(other.width))
			return false;
		return true;
	}
	
}
